package com.su.controller;

import java.util.List;
import javax.annotation.Resource;


import org.springframework.stereotype.Service;

import com.su.tools.DaoSupport1;
import com.su.tools.PageData;
import com.su.util.Page;

import net.sf.json.JSONObject;
//import org.json.JSONObject;

@Service("userService")
public class UserService {

	@Resource(name = "daoSupport1")
	private DaoSupport1 dao;
	private JSONObject json = new JSONObject();
	private PageData retPd;
	public JSONObject invoke(PageData pd) throws Exception {
		//
		if (pd.getString("params").equals("U101")) {
			this.U101(pd);
		}else{
			
			json.put("code","100");
			json.put("msg", "没有找到该业务代码");
			return json;
		}
		return json;
	}

	private void U101(PageData pd) throws Exception {
		if (! pd.checkValue("loginId")){
			json.put("code", "1");
			json.put("msg", "用户名不能为空!");
			return;
		}
		if (! pd.checkValue("password")){
			json.put("code", "1");
			json.put("msg", "密码不能为空!");
			return;
		}
		
		retPd = dao.getOne("UserMapper.userInfo", pd);
		if (retPd == null){
			json.put("code", "1");
			json.put("msg", "用户名或密码错误");
		}else{
			json.put("code", "0");
			json.put("msg", "");
			json.put("result", retPd);
		}
	}

	
	
	// ======================================================================================


	/*
	 * 保存用户
	 */
	public void saveU(PageData pd) throws Exception {
		dao.insert("AppuserMapper.saveU", pd);
	}

	/*
	 * 修改用户
	 */
	public void editU(PageData pd) throws Exception {
		dao.update("AppuserMapper.editU", pd);
	}

	/*
	 * 删除用户
	 */
	public void deleteU(PageData pd) throws Exception {
		dao.delete("AppuserMapper.deleteU", pd);
	}

	/*
	 * 批量删除用户
	 */
	public void deleteAllU(String[] USER_IDS) throws Exception {
		dao.delete("AppuserMapper.deleteAllU", USER_IDS);
	}

	/*
	 * 用户列表(全部)
	 
	public List<PageData> listAllUser(PageData pd) throws Exception {
		return (List<PageData>) dao.findForList("AppuserMapper.listAllUser", pd);
	}
*/
	/*
	 * 用户列表(用户组)
	
	public List<PageData> listPdPageUser(Page page) throws Exception {
		return (List<PageData>) dao.findForList("AppuserMapper.userlistPage", page);
	}
 */
	/*
	 * 保存用户IP
	
	public void saveIP(PageData pd) throws Exception {
		dao.update("AppuserMapper.saveIP", pd);
	}
 */
	/*
	 * 登录判断
	
	public PageData getUserByNameAndPwd(PageData pd) throws Exception {
		return (PageData) dao.findForObject("AppuserMapper.getUserInfo", pd);
	}
 */
	/*
	 * 跟新登录时间
	 */
	public void updateLastLogin(PageData pd) throws Exception {
		dao.update("AppuserMapper.updateLastLogin", pd);
	}
	// ======================================================================================

}
